import React, { useState, useEffect } from 'react';
import { connect } from 'dva';
import EditTemplate from '@/components/EditTemplate';
const BuildEdit = ({ location, dispatch }: any) => {
  const [detail, setDetail] = useState(null);
  const { id } = location.query;

  const saveUrl = id
    ? '/api/examine/v1/org/update'
    : '/api/examine/v1/org/create';
  useEffect(() => {
    if (id) {
      dispatch({
        type: '$request/post',
        payload: {
          url: '',
          data: {
            uuid: id,
            page: 0,
            size: 10,
          },
        },
      }).then(res => {
        console.log('储备项目申报详情：', res);
        setDetail(res);
      });
    }
  }, []);
  const filters = [
    {
      title: '基础信息',
      list: [
        {
          key: 'name',
          type: 'input',
          label: '机构名称',
          placeholder: '请输入姓名',
          rules: [{ required: true }],
          span: 24,
        },
        {
          key: 'licenseNo',
          type: 'input',
          label: '社会统一信用代码',
          span: 12,
        },
        {
          key: 'capital',
          type: 'input',
          label: '注册资本',
          placeholder: '请输入注册资本',
          span: 12,
        },
        {
          key: 'contactName',
          type: 'input',
          label: '联系人',
          span: 12,
        },
        {
          key: 'contactPhone',
          type: 'input',
          label: '联系人电话',
          placeholder: '请输入手机号',
          span: 12,
        },
        {
          key: 'memberCount',
          type: 'input',
          label: '技术人员总数',
          span: 24,
        },
        {
          key: 'seniorMemberCount',
          type: 'inputnumber',
          label: '高级职称人数',
          span: 12,
        },
        {
          key: 'intermediateMemberCount',
          type: 'inputnumber',
          label: '中级职称人数',
          span: 12,
        },
        {
          key: 'domain',
          type: 'textarea',
          label: '擅长领域',
          span: 24,
        },
      ],
    },
  ];

  return (
    <div>
      <EditTemplate
        filters={filters}
        initialValues={detail}
        updateUrl={saveUrl}
        formLayout={{
          labelCol: { span: 6 },
        }}
      />
    </div>
  );
};

export default connect((state: any) => state.auth)(BuildEdit);
